﻿using NB.MGJ.FrameWork;
using NB.MGJ.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace NB.MGJ.Service
{
    public class HtmlHelperService
    {
        //public BaseRepository _baseRepository = new BaseRepository();
        public static List<SelectListItem> GetComNameListService()
        {
                        List<SelectListItem> sll = new List<SelectListItem>();

            string sql = "select ID,EnterpriseName from Organization_Enterprise where ViewDel=0 and ViewFlag=1";
            var model = new BaseRepository().ExecuteTextCollection<TextCom>(sql);
       
  
            foreach (var item in model)
            {
                sll.Add(new SelectListItem { Value = item.ID.ToString(), Text = item.EnterpriseName });
            }

            return sll;
        }

        public static List<SelectListItem> GetDuoXuanShengService() 
        {
            List<SelectListItem> sll = new List<SelectListItem>();
            sll.Add(new SelectListItem { Value ="1", Text = "北京" });
            sll.Add(new SelectListItem { Value = "2", Text = "上海" });
            sll.Add(new SelectListItem { Value = "3", Text = "广州" });
            sll.Add(new SelectListItem { Value = "4", Text = "重庆" });
            return sll;
        }

        public List<SelectListItem> GetDuoXuanShiService(string textid) 
        {
            if (textid =="1")
            {
                List<SelectListItem> sll = new List<SelectListItem>();
                sll.Add(new SelectListItem { Value = "1", Text = "天安门" });
                sll.Add(new SelectListItem { Value = "2", Text = "三里团" });
                return sll;
            }
            else if (textid == "2")
            {
                List<SelectListItem> sll = new List<SelectListItem>();
                sll.Add(new SelectListItem { Value = "1", Text = "黄埔" });
                sll.Add(new SelectListItem { Value = "2", Text = "嘉定" });
                return sll;
            }

            else
            {
                List<SelectListItem> sll = new List<SelectListItem>();
                sll.Add(new SelectListItem { Value = "1", Text = "直辖市" });
                sll.Add(new SelectListItem { Value = "2", Text = "直辖市" });
                return sll;
            }

        }
        
        public static List<SelectListItem> GetSaleAreaService(int saleAreaId)
        {
            string sql = " SELECT ID,NAME FROM ANTIFLEEING_SALESAREA WHERE VIEWDEL=0";
            var list = new BaseRepository().ExecuteTextCollection<AntiFleeing_SalesArea>(sql);

            List<SelectListItem> listItem = new List<SelectListItem>();
            foreach (var model in list)
            {
                SelectListItem item = new SelectListItem() { Text = model.Name, Value = model.ID.ToString() };
                if (saleAreaId == model.ID)
                {
                    item.Selected = true;
                }

                listItem.Add(item);
            }

            return listItem;
        }

        public static IEnumerable<SelectListItem> GetPriCityService(string parid)
        {
            string[] parids = parid.TrimEnd(',').Split(',');
            parid = string.Empty;
            foreach (string str in parids)
                parid += "'" + str + "',";
            parid = parid.TrimEnd(',');
            string sql = " SELECT * FROM SYS_REGION WHERE 1=1 AND PARENTID IN ({0})";
            sql = string.Format(sql, parid);
            var list = new BaseRepository().ExecuteTextCollection<PCRModel>(sql);

            List<SelectListItem> listItem = new List<SelectListItem>();
            foreach (var model in list)
            {
                SelectListItem item = new SelectListItem() { Text = model.name, Value = model.codeID };
              
                for (int i = 0; i < parids.Length; i++)
                {
                    if (parids[0]==model.codeID)
                    {
                        item.Selected=true;
                    }
                }
                listItem.Add(item);
            }

            return listItem.AsEnumerable();
        }
    }
    public class TextCom 
    {
        public int ID { get; set; }
        public string EnterpriseName { get; set; }

    }
}
